<template>
<h1>猜数字练习</h1>
  <input type="text" v-model="number" placeholder="请输入数字">
  <button @click="guess">猜一猜</button>
  <button v-on:click="guess">猜一猜</button>
  <h3>小提示：{{info}}</h3>
</template>
<script setup>
import {ref} from "vue";

let num_random = parseInt(Math.random()*100+1);
console.log(num_random);
const number = ref('');
const info = ref('');
const guess = ()=>{
  if(isNaN(parseInt(number.value))){
    alert('请输入数字');
    return;
  }
  let number_int = parseInt(number.value);
  if(number_int>num_random){
      info.value='猜大了';
  }else if(number_int===num_random){
      info.value='猜对了';
  }else{
    info.value='猜小了';
  }
}
</script>


<style scoped>

</style>